package com.cloud.note.repository;

import com.cloud.note.model.Tag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface TagRepository extends JpaRepository<Tag, String> {
    List<Tag> findByUserId(String userId);

    Optional<Tag> findByIdAndUserId(String id, String userId);

    Optional<Tag> findByUserIdAndName(String userId, String name);

    boolean existsByUserIdAndName(String userId, String name);

    @Query("SELECT t FROM Tag t WHERE t.userId = :userId AND t.id IN :tagIds")
    List<Tag> findByUserIdAndIdIn(@Param("userId") String userId, @Param("tagIds") List<String> tagIds);
}